extends "res://Character/golden_player.gd"

signal called

var save_name :String = "player" 

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	scale = Vector2(0.3,0.3)
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	pass

func _physics_process(delta: float) -> void:
	var val = Vector2.ZERO
	
	if Input.is_action_pressed("walk_up"):
		val.y-=1
	if Input.is_action_pressed("walk_down"):
		val.y+=1
	if Input.is_action_pressed("walk_left"):
		val.x-=1
	if Input.is_action_pressed("walk_right"):
		val.x+=1
	
	if Input.is_action_just_pressed("fubing"):
		ZhaoHuan()

	var temp = joy_stick.get_joystick_dir()
	if temp.length()>0:
		val = temp
	
	if val.length()>0:
		val.normalized()
		animated.play("walk")
	else:
		animated.pause()
	
	velocity = val * delta * speed
	move_and_slide()

## 召唤军队
func ZhaoHuan()->void:
	called.emit(position)


func get_save_name():
	return save_name
	

func save_data():
	var dict = {
		"node" : "player",
		"position_x" : position.x,
		"position_y" : position.y,
	}
	return dict

func load_data(data):
	position.x = data.get("position_x",0)
	position.y = data.get("position_y",0)
